<template>
  <div class="mui-numbox" data-numbox-min="1" style="height: 28px;">
    <button class="mui-btn mui-numbox-btn-minus" type="button">-</button>
    <input
      class="mui-numbox-input"
      type="number"
      :value="initcount"
      @change="countChanged"
      ref="numbox"
    />
    <button class="mui-btn mui-numbox-btn-plus" type="button">+</button>
  </div>
</template>

<script>
import mui from "../../lib/mui/js/mui.js";
export default {
  mounted() {
    mui(".mui-numbox").numbox();
  },
  methods: {
    // 只要 一改变 input 的值就立即把数据传给父组件
    countChanged() {
      this.$store.commit("updateGoodsInfo", {
        id: this.goodsId,
        count: parseInt(this.$refs.numbox.value)
      });
    }
  },
  props: ["initcount", "goodsId"]
};
</script>

<style>
</style>